import { login } from '@/api/user'
import { getToken, setToken } from '@/utils/auth'
const state = {
  token: getToken()
}
const mutations = {
  setToken (state, value) {
    state.token = value
    // 存储token到浏览器
    setToken(value)
  }
}
const actions = {
  // 调用登录接口获取token
  // store={commit}
  async getUserToken ({ commit }, value) {
    // const res = await login(value)
    // commit('setToken', res)
    // console.log(res)
    login(value)
      .then(res => {
        commit('setToken', res)
        console.log(res)
      })
      .catch(() => {
        alert('出错了')
      })
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
